import { UserInfo } from "@/types";
import request from "@/utils/request";

interface LoginData {
  username: string;
  password: string;
}

interface RegisterData {
  username: string;
  email: string;
  password: string;
  confirmPassword: string;
}

export function login(data: LoginData) {
  return request<{
    access_token: string;
    user: Partial<UserInfo>;
  }>({
    url: "/auth/login",
    method: "post",
    data,
  });
}

export function register(data: RegisterData) {
  return request({
    url: "/auth/register",
    method: "post",
    data,
  });
}

export function getUserInfo() {
  return request({
    url: "/auth/profile",
    method: "get",
  });
}

export function logout() {
  return request({
    url: "/api/logout",
    method: "post",
  });
}
//GET/auth/profile获取当前用户信息
export function getProfile() {
  return request({
    url: "/auth/profile",
    method: "get",
  });
}

//PUT/auth/users/{id}编辑用户信息
export function editProfile(id: number, data: any) {
  return request({
    url: `/auth/users/${id}`,
    method: "put",
    data,
  });
}
//GET/auth/users获取用户列表
export function getUsers(params: any) {
  return request({
    url: "/auth/users",
    method: "get",
    params,
  });
}

//DELETE/auth/users/{id}删除用户
export function deleteUser(id: number) {
  return request({
    url: `/auth/users/${id}`,
    method: "delete",
  });
}
